#!/usr/bin/python

import commands
import getopt
import sys

optlist, args = getopt.getopt(sys.argv[1:], 'vh')

def usage():
    msg = '''Usage: %s [-options] file [args ...]

where options include:
    -v   enable verbose output
    -h   print this help message''' % __file__
    return sys.exit(msg)

flags = [opt[0] for opt in optlist]

if len(args) < 1 or '-h' in flags:
    usage()

src = args[0]
out = src[:src.rfind('.')]
pargs = '' if len(args) == 1 else ' '.join(args[1:])
cargs = ' '.join(flags) + ' ' + pargs

put = commands.getoutput('mzscheme -t compiler.scm -m %s %s' % (src, cargs))
if put:
    print put
commands.getoutput('javap -verbose -c %s > %s.bc' % (out, out))
